<?php
require_once ROOT_PATH.'include/sql/class_db.php';
require_once ROOT_PATH.'servlet/include/sql/sql_queries.php';

function add_comment($request)
{
	$date = time();
	
	$service_score = isset($request['service_score']) ? $request['service_score'] : '0';
	$env_score = isset($request['env_score']) ? $request['env_score'] : '0';
	$price_score = isset($request['price_score']) ? $request['price_score'] : '0';
	
	$params = array($request['bid'], $request['uid'], $service_score, $env_score, $price_score, $request['desc'], $date, $date);
	
	$sql = add_comment_sql();
	$result = DBFunction::getInstance()->insert($sql, $params);
	
	$key = md5("get_comment_list_".$request['bid']."_10_0");
	cache_delete($key);
	
	return $result ? $result : false;
}

function add_complaint($request)
{
	$date = time();
	
	$params = array($request['bid'], $request['uid'], $request['reason'], $request['address'], 
					$request['name'], $request['telephone'], 
					$request['image_path'], $date, $date);
	
	$sql = add_complaint_sql();
	$result = DBFunction::getInstance()->insert($sql, $params);
	
	return $result ? $result : false;
}

function update_complaint_favorite_count($request)
{
	$sql = update_complaint_favorite_count_sql();
	$result = DBFunction::getInstance()->execute($sql, array($request['id']));
	
	return ($result !== false) ? true : false; 
}

function update_scenic_favorite_count($request)
{
	$sql = update_scenic_favorite_count_sql();
	$result = DBFunction::getInstance()->execute($sql, array($request['id']));
	
	add_up_down_record(array('uid'=>$request['uid'], 'item_id'=>$request['id'], 'type'=>'scenic'));
	
	return ($result !== false) ? true : false; 
}
